package org.thss.petri.gef.figures;

import org.eclipse.draw2d.ColorConstants;
import org.eclipse.draw2d.Ellipse;
import org.eclipse.draw2d.Figure;
import org.eclipse.draw2d.FlowLayout;
import org.eclipse.draw2d.Graphics;
import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.Label;
import org.eclipse.draw2d.XYLayout;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.gef.handles.HandleBounds;

public class PlaceFigure extends NodeFigure {
	public static int DEFAULT_WIDTH = 60;
	public static int DEFAULT_HEIGHT = 60 + NAME_LABEL_HEIGHT;
	
	private Figure pane;
	private Label tokenCountLabel;
	
	public PlaceFigure() {
		shape = new Ellipse();
		shape.setBackgroundColor(ColorConstants.white);
		add(shape);
		pane = new Figure();
		FlowLayout layout = new FlowLayout();
		layout.setMajorAlignment(FlowLayout.ALIGN_CENTER);
		pane.setLayoutManager(layout);
		tokenCountLabel = new Label();
		pane.add(tokenCountLabel);
		add(pane);
	}
	
	@Override
	protected void paintFigure(Graphics graphics) {
		super.paintFigure(graphics);
		Rectangle bound = shape.getBounds();
		setConstraint(pane, new Rectangle(
				bound.width / 4, bound.height / 4,
				bound.width / 2, bound.height / 2));
		pane.remove(tokenCountLabel);
		pane.add(tokenCountLabel, 0);
		pane.invalidate();
	}

	public IFigure getTokenPane() {
		return pane;
	}
	
	public void setTokenCount(int count) {
		tokenCountLabel.setText(Integer.toString(count));
	}

	@Override
	protected boolean useLocalCoordinates() {
		return true;
	}
}
